#include "sys.h"
#include "log.h"
#include "capture.h"
#include "hook.h"
#include "pcap_output.h"

static char outFile[32] = "cap_all.pcap";
static char IfName[32] = "wlan0";

static OPT_T opts[] = {
    {"--cap-file", outFile, OPT_STRING, "cap output file"},
    {"--cap-iface", IfName, OPT_STRING, "cap bind to ifname"},
};

pcap_output_t* pcap;

static int _hook(Packet_t* packet)
{
    if (packet)
    pcap_output(pcap, packet);
    return 0;
}
int cap_run(){
    pcap = pcap_output_new(outFile, 0, 0);
    pcap_set_sync(pcap);
    Capture_t* cap = capture_new();
    capture_bind(cap, IfName);
    capture_set_promisc(cap, IfName);
    capture_set_thread_pool(cap, 10, 0, 100);
    hook_register(NULL, _hook);
    capture_run(cap);
    return 0;
}
int cap_opt(int argc, char** argv)
{
    return opt_parse(opts, sizeof(opts), argc, argv);
}
